<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/8/29 11:15
 * Modified Time: 2019/8/29 11:15
 * Version: 2.0
 */
namespace App\Modules\System\Controllers;
use App\Models\AmountFlow;
use App\Models\MemberCardFlow;
use App\Models\Royalty;
use App\Modules\System\Services\VersionService;
use App\Modules\System\Transformers\VersionTransformer;
use Flower\Core\Http\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class VersionController extends BaseController{
    private $versionService;
    public function __construct(VersionService $versionService){
        $this->versionService = $versionService;
    }
    public function getRules()
    {
        return [
            'getAppVersion' => [
                'version' => [
                    'title' => '版本号',
                    'rule' => 'required',
                    'message' => []
                ]
            ]
        ];
    }
    public function getAppVersion(Request $request){
        $app_type = $request->input('app_type','1');
        $version  = $request->input('version');
        $data = $this->versionService->getAppVersion($app_type);
        return $this->output((new VersionTransformer($data,$version))->transform());
    }

    public function taaaa()
    {
        DB::beginTransaction();
        $royalty = Royalty::where('type',2)->get();
        foreach ($royalty as $key => $value)
        {
            $time = $value->created_at;
            $member_flow =  MemberCardFlow::where('created_at',$time)->first();
            if($member_flow){
                if($value->item_id!=$member_flow->card_id) {

                }else{
                    $value->item_id = $member_flow->id;
                    $value->save();
                }

            }else{

            }

        }
        DB::commit();
    }
}